//
//  NewOrderDetailSectionView.m
//  NewPro
//
//  Created by RYX on 2019/5/16.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "NewOrderDetailSectionView.h"
#import "posOrderShipVOListModel.h"

@interface NewOrderDetailSectionView ()

@property (nonatomic,weak) UIView *topLine;
@property (nonatomic,weak) UILabel *fhsjLa;
@property (nonatomic,weak) UILabel *fhslLa;
@property (nonatomic,weak) UILabel *fxjeLa;
@property (nonatomic,weak) UILabel *syqxLa;
@property (nonatomic,weak) UILabel *zdbhLa;
@end

@implementation NewOrderDetailSectionView

- (instancetype)initWithSection:(NSInteger)section{
    
    if (self = [super init]) {
        
        [self setUI:section];
    }
    return self;
}

- (void)setUI:(NSInteger)section{

    UIView *topLine = [[UIView alloc] init];
    topLine.backgroundColor = BASECOLOR;
    self.topLine = topLine;
    [self addSubview:topLine];
    
    UIColor *color = [UIColor colorWithHexString:@"666666"];
    UIFont *font = [UIFont systemFontOfSize:12];
    
    UILabel *la1 = [[UILabel alloc] init];
    la1.text = @"发货时间：";
    la1.textColor = color;
    la1.font = font;
    [self addSubview:la1];
    
    UILabel *fhsjLa = [[UILabel alloc] init];
    fhsjLa.text = @"--";
    fhsjLa.textColor = color;
    fhsjLa.font = font;
    [self addSubview:fhsjLa];
    self.fhsjLa = fhsjLa;
    
    UILabel *la2 = [[UILabel alloc] init];
    la2.text = @"发货数量：";
    la2.textColor = color;
    la2.font = font;
    [self addSubview:la2];
    
    UILabel *fhslLa = [[UILabel alloc] init];
    fhslLa.text = @"--";
    fhslLa.textColor = color;
    fhslLa.font = font;
    [self addSubview:fhslLa];
    self.fhslLa = fhslLa;
    
    UILabel *la3 = [[UILabel alloc] init];
    la3.text = @"返现金额：";
    la3.textColor = color;
    la3.font = font;
    [self addSubview:la3];
    
    UILabel *fxjeLa = [[UILabel alloc] init];
    fxjeLa.text = @"--";
    fxjeLa.textColor = color;
    fxjeLa.font = font;
    [self addSubview:fxjeLa];
    self.fxjeLa = fxjeLa;
    
    UILabel *la4 = [[UILabel alloc] init];
    la4.text = @"有效期限：";
    la4.textColor = color;
    la4.font = font;
    [self addSubview:la4];
    
    UILabel *syqxLa = [[UILabel alloc] init];
    syqxLa.text = @"--";
    syqxLa.textColor = color;
    syqxLa.font = font;
    [self addSubview:syqxLa];
    self.syqxLa = syqxLa;
    
    UILabel *la5 = [[UILabel alloc] init];
    la5.text = @"终端编号：";
    la5.textColor = color;
    la5.font = font;
    [self addSubview:la5];
    
    UILabel *zdbhLa = [[UILabel alloc] init];
    zdbhLa.text = @"--";
    zdbhLa.textColor = color;
    zdbhLa.font = font;
    [self addSubview:zdbhLa];
    self.zdbhLa = zdbhLa;
    
    UIButton *moreBtn = [[UIButton alloc] init];
    [moreBtn setImage:[UIImage imageNamed:@"orderDetail_open"] forState:UIControlStateNormal];
    [moreBtn setImage:[UIImage imageNamed:@"orderDetail_close"] forState:UIControlStateSelected];
    moreBtn.userInteractionEnabled = NO;
    self.moreBtn = moreBtn;
    [self addSubview:moreBtn];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTag:section];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 60)];
    button.backgroundColor = UIColor.clearColor;
    [button addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    
    [topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(5);
    }];
    
    [la1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(14);
        make.top.mas_equalTo(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(65);
    }];
    
    [la2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(14);
        make.top.equalTo(la1.mas_bottom).offset(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(65);
    }];
    
    [la3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(14);
        make.top.equalTo(la2.mas_bottom).offset(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(65);
    }];
    
    [la4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(14);
        make.top.equalTo(la3.mas_bottom).offset(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(65);
    }];
    
    [la5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(14);
        make.top.equalTo(la4.mas_bottom).offset(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(65);
    }];
    
    [fhsjLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(la1.mas_right).offset(8);
        make.centerY.equalTo(la1);
    }];
    
    [fhslLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(la1.mas_right).offset(8);
        make.centerY.equalTo(la2);
    }];
    
    [fxjeLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(la1.mas_right).offset(8);
        make.centerY.equalTo(la3);
    }];
    
    [syqxLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(la1.mas_right).offset(8);
        make.centerY.equalTo(la4);
    }];
    
    [zdbhLa mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(la1.mas_right).offset(8);
        make.centerY.equalTo(la5);
    }];
    
    [moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(-14);
        make.centerY.equalTo(la5);
        make.width.height.mas_equalTo(30);
        
    }];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(0);
        
    }];
    
}

- (void)setIfHiddenTopLine:(BOOL)ifHiddenTopLine{
    
    self.topLine.hidden = ifHiddenTopLine;
}

- (void)buttonPress:(UIButton *)btn{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(onPreBtn:)]) {

        [self.delegate onPreBtn:btn];
    }
}

- (void)setModel:(posOrderShipVOListModel *)model{
    
    self.fhsjLa.text = [DateManager changeWithTime:model.consignTime];
    self.fhslLa.text = [NSString stringWithFormat:@"%@台",model.number];
    self.fxjeLa.text = [NSString stringWithFormat:@"%@元",model.backAmount];
    self.syqxLa.text = [NSString stringWithFormat:@"%@天",model.expireTime];
    self.zdbhLa.text = model.snList[0];
}
@end
